package com.zbkj.service.coupons.service;

import com.zbkj.common.model.user.User;
import com.zbkj.service.coupons.service.impl.CouponsPayServiceImpl;
import com.zbkj.service.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;

@Slf4j
@Service
public class CouponsProcessService {

    private static final Logger logger = LoggerFactory.getLogger(CouponsProcessService.class);

    @Autowired
    UserService userService;

    //酒品区赠送消费余额
    public void giveCoupons(BigDecimal payPrice) {
        User info = userService.getInfo();
        BigDecimal nowCoupons = info.getCoupons().add(payPrice);

        User newUser = new User();
        newUser.setId(info.getId());
        newUser.setCoupons(nowCoupons);
        boolean update = userService.updateById(newUser);
        if (update) {
            logger.info("用户{}赠送消费额度：{}成功", newUser.getId(), payPrice);
        } else {
            logger.warn("用户{}赠送消费额度：{}失败", newUser.getId(), payPrice);
        }
    }

}
